import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'lib-flexible/flexible'
import axios from 'axios'
import VueAxios from 'vue-axios'
import VueCookies from 'vue-cookies'

import { 
  Toast,
  NavBar,
  Field,
  Form,
  Button,
  Popup,
  Tabbar,
  TabbarItem,
  Search,
  Swipe, 
  SwipeItem,
  GoodsAction,
  GoodsActionIcon, 
  GoodsActionButton,
  SwipeCell,
  Card,
  RadioGroup,
  Radio,
  Stepper,
  Checkbox, 
  CheckboxGroup,
  SubmitBar,
  Badge,
  Empty,
  TreeSelect,
  Sidebar, 
  SidebarItem,
  List,
  Cell, 
  CellGroup,
  Icon,
  AddressList,
  AddressEdit,
  Picker,
  Uploader,
  Tab, 
  Tabs,
  Dialog
 } from 'vant';

Vue.use(NavBar).use(Field).use(Form).use(Button).use(Popup).use(Tabbar).use(TabbarItem).use(Search).use(Swipe).use(SwipeItem).use(GoodsAction).use(GoodsActionIcon).use(GoodsActionButton).use(SwipeCell).use(Card).use(RadioGroup).use(Radio).use(Stepper).use(Checkbox).use(CheckboxGroup).use(SubmitBar).use(Badge).use(Toast).use(Empty).use(TreeSelect).use(Sidebar).use(SidebarItem).use(List).use(Cell).use(CellGroup).use(Icon).use(AddressList).use(AddressEdit).use(Picker).use(Uploader).use(Tab).use(Tabs).use(Dialog);

Vue.use(VueAxios, axios);

Vue.use(VueCookies)

//请求之前执行, 请求拦截器
axios.interceptors.request.use(config => {
  // console.log('config.data ==> ', config.data);
  if (config.method === 'post') {
    //序列化post请求参数
    let paramsString = '';
    for (let key in config.data) {
      paramsString += `${key}=${config.data[key]}&`;
    }
    config.data = paramsString.slice(0, -1);
    // console.log('config.data ==> ', config.data);
  }
  //必须返回config
  return config;
})

Vue.prototype.baseURL = 'http://www.kangliuyong.com:10002';
Vue.prototype.appkey = 'U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=';

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
